package com.shell.testintentfilter;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private Button btn1;
    private Button btn2;
    private Button btn3;
    private Button btn4;
    private Button btn5;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
    }

    public void init() {

        btn1 = findViewById(R.id.btn1);
        btn1.setOnClickListener(this);//点击跳转到第二个activity
        btn2 = findViewById(R.id.btn2);
        btn2.setOnClickListener(this);//点击前往学校官网
        btn3 = findViewById(R.id.btn3);
        btn3.setOnClickListener(this);//点击打电话
        btn4 = findViewById(R.id.btn4);
        btn4.setOnClickListener(this);//点击启动联系人
        btn5 = findViewById(R.id.btn5);
        btn5.setOnClickListener(this);//点击发送电子邮件
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn1:
                clickBtn1();
                break;
            case R.id.btn2:
                clickBtn2();
                break;
            case R.id.btn3:
                clickBtn3();
                break;
            case R.id.btn4:
                clickBtn4();
                break;
            case R.id.btn5:
                clickBtn5();
                break;
        }
    }
    //点击跳转到第二个activity
    public void clickBtn1() {
        Intent intent = new Intent();//创建时不指定activity
        intent.setAction("myActivity");//在manifests下的xml文件中进行注册
        startActivity(intent);
    }
    //点击前往学校官网
    public void clickBtn2() {
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_VIEW);
        intent.setData(Uri.parse("https://www.lit.edu.cn/"));
        startActivity(intent);
    }
    //点击打电话
    public void clickBtn3() {
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_DIAL);
        intent.setData(Uri.parse("tel:+21313123"));
        startActivity(intent);
    }
    //点击启动联系人
    public void clickBtn4() {
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_PICK);
        intent.setData(Uri.parse("content://com.android.contacts/contacts/"));
        startActivity(intent);
    }
    //点击发送电子邮件
    public void clickBtn5() {
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_SENDTO);
        intent.setData(Uri.parse("mailto:324324@qq.com"));
        startActivity(intent);
    }
}